package com.atguigu.lease.web.app.custom.interceptors;

import com.atguigu.lease.common.excetion.LeaseException;
import com.atguigu.lease.common.result.ResultCodeEnum;
import com.atguigu.lease.common.utils.JwtUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;

import java.net.Authenticator;

/**
 * @author 芦博
 * @description
 * @createDate 2025/11/10 20:32
 */
public class LoginInterceptors implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("Access_token");
        //如果token为空证明没登录
        if (token == null){
            throw new LeaseException(ResultCodeEnum.ADMIN_LOGIN_AUTH);
        }
        JwtUtils.parseToken(token);
        return true;
    }
}
